/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-01 22:19:08
 * Copyright (c) 2015- -版权所有
 */

package com.joysuch.wwyt.edu.repository;

import com.joysuch.wwyt.edu.entity.EduExamUserScope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * EduExamUserScopeDao
 *
 */
public interface EduExamUserScopeDao
        extends JpaRepository<EduExamUserScope, Long>, QuerydslPredicateExecutor<EduExamUserScope> {
    public Page<EduExamUserScope> findAll(Specification<EduExamUserScope> spec, Pageable pageable);

    public EduExamUserScope save(EduExamUserScope bean);

    public void delete(EduExamUserScope bean);

    int deleteByExamId(Long examId);

    @Query(value = "select e from EduExamUserScope e where e.deleteFlag='0' and e.examId=?1")
    List<EduExamUserScope> findByExamId(Long examId);

    List<EduExamUserScope> findByExamIdIn(List<Long> examIds);

    @Query(value = "select e.objId from EduExamUserScope e where e.examId=:examIds")
    List<Long> findObjIdByExamId(Long examIds);

    @Query("select distinct examId from EduExamUserScope where (objType='U' and objId=?1) or (objType='D' and objId=?2) or(objType='J' and objId=?3)")
    public List<Long> findUserCanJoinExams(Long userId, Long departId, Long jobId);
}
